package com.bjpowernode.dataservice.mapper;

import com.bjpowernode.commons.model.Product;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.Date;
import java.util.List;

public interface ProductMapper {
    // 产品的平均利率
    @Select("SELECT AVG(rate) from b_product_info")
    Double getAvgRate();

    // 首页数据--新手宝
    @Select("select * from b_product_info where product_type=0")
    Product getNew();

    // 首页数据--优选产品
    // 参数为周期：1表示满月宝，3表示季度宝，6表示双季宝...
    @Select("select * from b_product_info where product_type=1 and cycle=#{cycle}")
    Product getYX(Integer cycle);

    // 首页数据--散标产品
    // 返回集合时，必须指定集合的泛型，否则MyBatis无法处理数据集
    @Select("select * from b_product_info where product_type=2 and product_status=0 and left_product_money>=bid_min_limit order by left_product_money  limit 3")
    List<Product> getSB();

    @Select("select count(*) from b_product_info where product_type=#{type}")
    Integer getCount(Integer type);

    @Select("select * from b_product_info where product_type=#{type} limit #{start}, #{length}")
    List<Product> getPageData(Integer type, Integer start, Integer length);

    //@Select("select * from b_product_info where id=#{id}")
    Product getById(Long id);

    @Update("update b_product_info set left_product_money=left_product_money-#{money}" +
            " where id=#{prodId} and left_product_money>=#{money}")
    int updateMoney(Long prodId, Double money);

    @Update("update b_product_info set product_status=#{status}," +
            " product_full_time=#{fullTime} where id=#{prodId}")
    void setFull(Long prodId, int status, Date fullTime);

    @Select("select * from b_product_info where product_status=1")
    List<Product> getFullProduct();

    @Update("update b_product_info set product_status=#{status} where id=#{id}")
    void setStatus(Long id, int status);
}
